/**
 * 
 */
package fr.fermeManager.application.views.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import org.jdesktop.beansbinding.Converter;

/**
 * @author Mo
 *
 */
public class ConverterGregorianCalendar extends Converter<GregorianCalendar, String> {
	
	private DateFormat df = new SimpleDateFormat("yyyy/MM/dd");

	@Override
	public String convertForward(GregorianCalendar arg0) {
		Date dateDate = arg0.getTime();
		return df.format(dateDate);
	}

	@Override
	public GregorianCalendar convertReverse(String arg0) {
		Date parsed = null;
		try {
			parsed = df.parse(arg0);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		GregorianCalendar newCalendar = new GregorianCalendar();
		newCalendar.setTime(parsed);
		return newCalendar;
	}


}
